package com.ttai.ui.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.ttai.R;
import com.ttai.dagger.componet.activity.DaggerUserComponet;
import com.ttai.dagger.module.activity.UserPresenterModule;
import com.ttai.presenter.activity.UserPresenter;
import com.ttai.ui.base.BaseActivity;

import javax.inject.Inject;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class User extends BaseActivity implements DialogInterface.OnClickListener{
    @Bind(R.id.btn_usercenter)
    Button btnUsercenter;
    @Bind(R.id.btn_over)
    Button btnOver;
    @Inject
    UserPresenter userPresenter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user);
        ButterKnife.bind(this);
        setComponet();
    }

    @Override
    public void next(View view) {

    }

    @Override
    public void pre(View view) {
        finish();
    }

    @Override
    public void setComponet() {
        DaggerUserComponet.builder()
                .userPresenterModule(new UserPresenterModule(this))
                .build()
                .in(this);
    }

    @OnClick({R.id.btn_usercenter, R.id.btn_over})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_usercenter:
                userPresenter.clearTokenAcount();

                this.finish();
                Intent intent=new Intent();
                intent.setClass(User.this,MainActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                break;
            case R.id.btn_over:
                new AlertDialog.Builder(this)
                        .setMessage("您确定要注销账户？注销后您的所有数据都会被清空")
                        .setIcon(R.drawable.jieshao)
                        .setTitle("注销操作")
                        .setPositiveButton("确定",this)
                        .setNegativeButton("取消",this)
                        .show();
                break;
        }
    }

    @Override
    public void onClick(DialogInterface dialogInterface, int which) {
        if (which==DialogInterface.BUTTON_POSITIVE){
            String token = userPresenter.getToken();
            userPresenter.logOut(token);
        }
        else if (which==DialogInterface.BUTTON_NEGATIVE){
        }
    }
}
